<?php

namespace Home\Model;

class LabelsModel extends CommonModel
{
    static public function lists($users, $types = 1)
    {
        $user_labels = [];

        $labels = (new LabelsUserModel)->where(['types' => $types, 'user_id' => ['in', $users]])->getField('id, user_id, label_id');

        if ($labels) {
            $label_ids = array_column($labels, 'label_id');

            $label_contain = (new LabelsModel)->where(['id' => ['in', $label_ids]])->getField('id, name');

            foreach ($labels as $item) {
                if (isset($label_contain[$item['label_id']])) {
                    $user_labels[$item['user_id']][] = $label_contain[$item['label_id']];
                }
            }
        }

        return $user_labels;
    }
}
